namespace SQLite加解密
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
            AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException += TaskScheduler_TaskUnhandledException;
            Application.ThreadException += Application_ThreadException;

            // To customize application configuration such as set high DPI settings or default font,
            // see https://aka.ms/applicationconfiguration.
            ApplicationConfiguration.Initialize();
            Application.Run(new Form1());
        }

        #region 全局异常处理
        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            MessageBox.Show($"异常：{e.Exception.Message}");
        }

        private static void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = e.ExceptionObject as Exception;
                if (e.IsTerminating)
                {
                    MessageBox.Show("非常抱歉，系统遇到未知错误，我们已将错误写入日志，请通知系统维护人员。");
                }
                else
                {
                    if (!(ex is ThreadAbortException)) //如果是终止线程异常就不抛出
                    {

                    }
                }
            }
            catch
            {
            }
        }

        private static void TaskScheduler_TaskUnhandledException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            e.SetObserved();
        }
        #endregion

    }
}